package com.tuo51.evaluate.repositories.evaluatev2;

import com.tuo51.evaluate.domain.evaluatingV2.EvaluateV2Dimension;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface EvaluateV2DimensionRepository extends JpaRepository<EvaluateV2Dimension, String> {

    //獲取所有的維度
    List<EvaluateV2Dimension>  findAllByDeletedOrderByCode(Boolean deleted);
    List<EvaluateV2Dimension>  findAllByIdNotAndDeletedIsFalseOrderByCode(String notId);

    EvaluateV2Dimension getByName(String name);

    //獲取第一个維度
    EvaluateV2Dimension  findFirstByDeletedOrderByCode(Boolean deleted);

    //查找下一个维度
    @Query(value = "select * from tb_evaluate_dimension where code > (select code from tb_evaluate_dimension where id = :dimensionId) order by code limit 1", nativeQuery = true)
    List<EvaluateV2Dimension> findDimensionAfterId(@Param("dimensionId") String dimensionId);

    //獲取第一个維度
    EvaluateV2Dimension  findFirstByDeletedIsFalseAndIdNotInOrderByCode(List<String> skipIds);

    //查找下一个维度
    @Query(value = "select * from tb_evaluate_dimension " +
            "where code > (select code from tb_evaluate_dimension where id = :dimensionId) " +
            "and id not in (:skips) " +
            "order by code limit 1", nativeQuery = true)
    List<EvaluateV2Dimension> findDimensionAfterIdAndIdNotIn(@Param("dimensionId") String dimensionId, @Param("skips") List<String> skipIds);
}
